package game.gui;

import java.util.Random;

import engine.Engine;
import engine.game.Manager;
import engine.graphics.Color4f;
import engine.gui.Panel;
import engine.gui.ProgressBar;
import game.objects.nonstaticObjects.EntityModel;

@SuppressWarnings("unused")
public class StatusBar extends Panel {

	private static final long serialVersionUID = 1L;

	private static final int WIDTH = Engine.WIDTH, HEIGHT = 50 ; 
	
//	private static Random r = new Random(); 

	private ProgressBar health ; 
	
	private final EntityModel entity ;   
	
	public StatusBar(Manager m, EntityModel e) {
		super(m, 0, 0, WIDTH, HEIGHT);
		this.entity = e ; 
		init();
	}

	public void update(){
		super.update(); 
		if(!(this.entity == null)){
			this.health.setMax(this.entity.getEntity().getAttributes().getMaxHealth());
			this.health.setProgress(this.entity.getEntity().getAttributes().getHealth());
		}
	}
	
	public void init(){
		super.init();
		this.enableBorder(); 
		this.changeNormalColor(new Color4f(0.15f, 0.15f, 0.15f, 1.0f));
		int l = (Engine.WIDTH - this.getObjectWidth() / 2) / 2; 
		int t = (int)this.getMaxY() / 3 ; 
		try{
			System.out.println(this.entity);
		}catch(Exception e){
			e.printStackTrace(); 
		}
		health = new ProgressBar(this.getManager(), l, t, this.getObjectWidth() / 2, 30, 1); 
		this.addNewChild("health", health);
	}

}
